<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>组件中ref使用</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<style>
body{font-size: 36px;}
</style>
<body>
    <div id="app">
        <my-component ref="one" @change="numberChange"></my-component>
        <my-component ref="two" @change="numberChange"></my-component>
        <div>{{count}}</div>
    </div>
</body>

<script>
    Vue.component("my-component", {
        template: "<div @click='hand'>{{number}}</div>",
        data: function () {
            return {
                number: 0
            }
        },
        methods:{
            hand:function(){
                this.number++
                this.$emit('change')
            }
        }
    });
    
    var vm = new Vue({
        el: "#app",
        data:{
            count:0
        },
        methods:{
            numberChange:function(){
                console.log(this.$refs.one.number)
                console.log(this.$refs.two.number)
                this.count = this.$refs.one.number+this.$refs.two.number

            }
        }

    })
</script>

</html>